package view;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


class Value {
	public Value(int id, String data) {
		this.id = id;
		this.data = data;
	}

	public String toString(){
		return "["+id+"]"+data;
	}
	int id;
	String data;
}

public class ListView implements IListView {

	private String idCmdValue;
	
	
	private List<Value> data = new ArrayList<Value>();
	private String currentValue;

	public void addRow(int id, String s) {
		Value v = new Value(id, s);
		data.add(v);
	}
	
	public String getCurrentValue() {
		currentValue = "?";
		int x=Integer.parseInt(idCmdValue);
		for (Iterator<Value> i = data.iterator(); i.hasNext();) {
			Value v = i.next();
			if (v.id==x)
			    currentValue = "["+v.id+"]"+v.data;
		}
		return currentValue;
	}

	public String getIdCmdValue() {
		return idCmdValue;
	}

	public void setIdCmdValue(String s) {
		idCmdValue = s;
	}

	public String toString() {
		String result = "";//"[" + idCmdValue + "]\n";
		int x=Integer.parseInt(idCmdValue);
		for (Iterator<Value> i = data.iterator(); i.hasNext();) {
			Value v = i.next();
			if (v.id==x)
			    result += "["+v + "]\n";
			else
				result += v + "\n";
		}
		return result;
	}

	@Override
	public void setId(int id) {
		idCmdValue = Integer.toString(id);
	}



}